﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace Sc.Service
{
    public class Encrypt
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        public static string EncryptByMD5(string str)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] date = Encoding.Default.GetBytes(str); //将字符编码为一个字节序列
            byte[] md5data = md5.ComputeHash(date);      //计算data字节数组的哈希值
            md5.Clear();
            string code = string.Empty;
            for (int i = 0; i < md5data.Length - 1; ++i)
            {
                code += md5data[i].ToString("x").PadLeft(2, '0');
            }
            return code;
        }
    }
}
